package leetcode.每日一题;

import org.junit.Test;

/**
 * @author ：zsy
 * @date ：Created 2022/11/8 8:12 PM
 * @description：
 */
public class 统计一致字符串的数目 {
    @Test
    public void test() {
        System.out.println(new Solution().countConsistentStrings("abc", new String[]{"a", "b", "c", "ab", "ac", "bc", "abc"}));
    }

    class Solution {
        public int countConsistentStrings(String allowed, String[] words) {
            int[] chars = new int[26];
            for (int i = 0; i < allowed.length(); i++) {
                char ch = allowed.charAt(i);
                chars[ch - 'a']++;
            }
            int ans = 0;
            for (String word : words) {
                int i = 0;
                for (; i < word.length(); i++) {
                    if (chars[word.charAt(i) - 'a'] == 0) {
                        break;
                    }
                }
                if (i == word.length()) {
                    ans += 1;
                }
            }
            return ans;
        }
    }
}
